package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class CustomerContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class CustomerContainer
{
    private ArrayList<Customer> customerContainer;
    private static CustomerContainer instance;
    private Customer cObject;
    public CustomerContainer()
    {
        customerContainer = new ArrayList<Customer>();
    }

    public static CustomerContainer getInstance()
    {
        if(instance == null)
        {
            instance = new CustomerContainer();
        }
        return instance;
    }

    public Customer findCustomerById(int id){
        cObject = null;
        int index = 0;
        boolean found = false;
        while(index < customerContainer.size() && !found)
        {
            if(customerContainer.get(index).getCustomerId() == id)
            {
                cObject = customerContainer.get(index);
                found = true;
            }
            else
            {
                index++;
            }
        }//end while
        return cObject;

    }

    public boolean addCustomer(Customer c)
    {
        boolean added = false;
        if(findCustomerById(c.getCustomerId()) == null)
        {
            customerContainer.add(c);
            added=true;
        }
        return added;
    }

    public boolean deleteCustomerById(int id)
    {
        if(customerContainer.contains(findCustomerById(id)))
        {
            customerContainer.remove(findCustomerById(id));
            return true;
        }
        else
        {
            return false;
        }
    }
}